package com.itcast.googleplay.fragment;

import com.itcast.googleplay.ui.LoadingPage;
import com.itcast.googleplay.ui.LoadingPage.ResultState;
import com.itcast.googleplay.utils.UIUtils;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

public abstract class BaseFragment extends Fragment {
	private LoadingPage loadingPage;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
	}
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		loadingPage = new LoadingPage(UIUtils.getContext()) {
			
			@Override
			public ResultState onload() {
				return onSubLoad();
			}
			
			@Override
			public View onCreateSuccessView() {
				return onCreateSuccessedSubView();
			}
		};
		return loadingPage;
	}
	
	public abstract ResultState onSubLoad();
	public abstract View onCreateSuccessedSubView();
	
	public void showData(){
		if(loadingPage!=null){
			loadingPage.show();
		}
	}
}
